/*
 * @Author: LiJia
 * @Date: 2021-03-08 18:32:07
 * @LastEditTime: 2021-04-05 12:31:36
 * @LastEditors: LiJia
 * @Description: Description
 * @FilePath: \class-manage-system\miniprogram\pages\mine\children\signin\signin.ts
 */

// const app = getApp<IAppOption>()

Page({
  data: {
    clsUserInfo: {},
    signinTable: [],
    hasMoreSigninInfo: false
  },
  onLoad() {
    this.setData({
      signinTable: this.data.signinTable.reverse()
    })
    const eventChannel = this.getOpenerEventChannel()
    eventChannel.on('clsUserInfo', (req) => {
      this.setData({
        clsUserInfo: req.data
      })
    })
    this.getSigninTable()
  },

  getSigninTable() {
    let that = this
    const apiUrl = wx.getStorageSync('apiUrl')
    wx.request({
      url: apiUrl + '/signin-select',
      data: {
        id: (this.data.clsUserInfo as any).id,
        role: (this.data.clsUserInfo as any).role
      },
      success: (res) => {
        let _res = res.data as any
        if (_res.code === 200) {
          _res.data.forEach((item: any) => {
            item.date = item.date.toString().split('T')[0]
            item.deadline = item.deadline.toString().split('.')[0].replace('T', '  ')
          })
          that.setData({
            signinTable: _res.data as never
          })
        } else if (_res.code === 204) {
          that.setData({
            signinTable: []
          })
        } else {
          wx.showToast({
            title: _res.msg,
            icon: 'none',
            duration: 2021
          })
        }
      }
    })
  }

})

export default {}
